package com.longcai.service.impl.homegood;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.longcai.bean.ApiResult;
import com.longcai.entity.homegood.ClyjGoodsPics;
import com.longcai.entity.homegood.ClyjGoodsSpec;
import com.longcai.mapper.homegood.ClyjGoodsSpecMapper;
import com.longcai.mapper.homepage.ClyjGoodsPicsMapper;
import com.longcai.service.homegood.ClyjGoodsSpecService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品规格表 服务实现类
 * </p>
 *
 * @author M
 * @since 2019-03-22
 */
@Service
public class ClyjGoodsSpecServiceImpl extends ServiceImpl<ClyjGoodsSpecMapper, ClyjGoodsSpec> implements ClyjGoodsSpecService {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private ClyjGoodsSpecMapper clyjGoodsSpecMapper;
    @Autowired
    private ClyjGoodsPicsMapper clyjGoodsPicsMapper;

    /**
     * 查询商品规格
     *
     * @param goodsid
     * @return
     */
    @Override
    public ApiResult getGoodsSpec(String goodsid) {
        try {
            QueryWrapper<ClyjGoodsSpec> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("goods_id", goodsid);
            List<ClyjGoodsSpec> list = this.clyjGoodsSpecMapper.selectList(queryWrapper);
            logger.debug("查询成功+++++++++++", list);
            return ApiResult.success(list);
        } catch (Exception e) {
            logger.debug("查询失败+++++++++++");
            e.printStackTrace();
            return ApiResult.fail("查询失败"+e.getMessage());
        }
    }

    /**
     * 获取规格图片
     *
     * @param id
     * @return
     */
    @Override
    public ApiResult getSpecPics(String id) {
        try {
            QueryWrapper<ClyjGoodsPics> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("spec_id", id);
            List<ClyjGoodsPics> clyjGoodsPicsList = this.clyjGoodsPicsMapper.selectList(queryWrapper);
            logger.debug("查询成功", clyjGoodsPicsList);
            return ApiResult.success(clyjGoodsPicsList);
        } catch (Exception e) {
            logger.error("查询失败");
            e.printStackTrace();
            return ApiResult.fail("查询失败"+e.getMessage());
        }
    }
}
